<div class="fsh-pop">
    <div class="layui-form" id="add_form">
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>课程名称</label>
            <div class="layui-input-block">
                <input type="text" name="course_title" required lay-verify="required"
                       autocomplete="off" class="layui-input" id="title">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>课程类型</label>
            <div class="layui-input-block">
                <select name="course_state" lay-verify="required" id="type">
                    <option value="1">直播</option>
                    <option value="2">录播</option>
                    <option value="3">在线考试</option>
                    <option value="4">线下考试</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>指派老师</label>
            <div class="layui-input-block">
                <input type="hidden" name="course_teacher_id" id="teacherId">
                <input type="text" name="course_title" required lay-verify="required"
                       autocomplete="off" class="layui-input" readonly id="teacherName" placeholder="请选择">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><i>*</i>任务描述</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" name="desc_ribe" id="desc"> </textarea>
            </div>
        </div>
        <input type="hidden" id="hash" name="hash"/>
        <input type="hidden" id="course_id" name="course_id"/>
    </div>
</div>

<script>
    var courseInfo;
    layui.use(['layer', 'form', 'element'], function () {
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;
        form.render();

        getCourseInfo(_jm.get_selected_node().id)

        //选择老师
        $('#teacherName').click(function () {
            showBigDialog({
                title: '选择老师'
                , template: 'views/common/check_system_teacher.html'
                , yes: function (index, layero) {
                    var checkData = table.checkStatus('teacherTable').data;
                    layer.close(index);
                    $('#teacherId').val(checkData[0].user_id);
                    $('#teacherName').val(checkData[0].nickname);
                }

            })
        });
    });

    //获取单条课程数据
    function getCourseInfo(id) {
        $.ajax({
            url: context + '/api/educourse/getOne?course_id=' + id
            , type: 'GET'
            , success: function (result) {
                if (result.success) {
                    //layer.msg("添加成功");
                    courseInfo = result.data;
                    $('#title').val(courseInfo.course_task);
                    $('#type').val(courseInfo.course_state);
                    $('#teacherId').val(courseInfo.course_teacher_id);
                    $('#teacherName').val(courseInfo.course_teacher);
                    $('#desc').val(courseInfo.desc_ribe);
                    $('#hash').val(courseInfo.hash);
                    $('#course_id').val(courseInfo.course_id);
                } else {
                    layer.msg(result.msg);
                }
            },
            error: function () {
                layer.msg("修改失败");
            }
        })
    }
</script>
